<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/pages/common/taglib.jsp"  %>
<%@include file="/pages/common/tagjs.jsp"  %>
<%@include file="/WEB-INF/tags/gfa4ext/inc/extmeta.jsp"  %>
<%@ taglib tagdir="/WEB-INF/tags/gfa4ext" prefix="ge" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><g:label text="system.Role" /></title>
<script type="text/javascript">
function validateCode(){
	var errString = '';
	
	var roleName = $('#roleName').val();
	if(!roleName || roleName == ''){
		errString += String.format(system.Role.roleNameNotNull1);
	} else {
		var roleId = $('#hiddenRoleId').val();
		
			RoleService.validateRoleNameExist(roleName, roleId == ''||!roleId?'':roleId,{
				callback:function(result){
								if(result){
									errString+=String.format(system.Role.roleNameExist1);
								}
							},
				async:false
			});
		
	}

	var roleType = $('#roleType').val();
	if(!roleType || roleType == ''){
		errString += String.format(system.Role.activeFlagNotNull1);
	}
	
	var activeDate=$("#datePicker_activeDate").val();
	var expiredDate=$("#datePicker_expiredDate").val();
	if(!activeDate){
		errString += String.format(system.Role.activeDateNotNull1);
	}
	if(!expiredDate){
		errString += String.format(system.Role.expiredDateNotNull1);
	}
			
	if(activeDate > expiredDate){
		errString += String.format(system.Role.expiredDateNotBeforactiveDate1);
	}
	if(errString != ''){
		alert(errString);
		return false;
	}
	return true;
}

function renderRoleType(value){
	switch(value){
		case '1': return 'Active';
		case '2': return 'Lock';
		case '3': return 'Disable';
	}
}
$(function(){
	$("#officeCode").autoSelect({
		url : "${ctx}",
		className:"com.wef.system.entity.Role",
		displayField : "officeCode",
		width : 450,
		displayNum : 8,
		inTable : false,
		hiddenId : 'hiddenRoleId',
		displayFieldI18n : "system.Role.officeCode"
	});
});
</script>
</head>
<body>
  <!--Content-->
  <div id="Content">
	<!--Right-->
	<div class="ModuleSearch">
	    <div class="ModuleSearchBorder">
	      <div class="ModuleSearchTitle"><g:label text="title.search" showColon="false" /></div>
	        <form id="searchForm" name="searchForm" onsubmit="return false;">
		      <div class="ModuleSearchInput">
					<table width="100%" cellspacing="0" cellpadding="0">
							<tr>
								<td width="10%"><g:label text="system.Role.roleName"/></td>
								<td width="22%"><g:text property="roleName" condition="likeaic" /></td>
								<td width="10%"><g:label text="system.Role.roleDesc"/></td>
								<td width="22%"><g:text property="roleDesc" condition="likeaic" /></td>
								<td width="10%">&nbsp;</td>
								<td width="22%">&nbsp;</td>
							</tr>
					</table>
	          </div>
	          <div class="ModuleEditButton">
				<g:button styleId="btnSearch" styleClass="search" type="button" text="button.search"/>
				<g:button styleId="btnReset" styleClass="reset" type="reset" text="button.reset"/>
			  </div>
		   </form>
	    </div>
	  </div>
	  <!--搜索模块-->
	
	<div class="ModuleGrid">
	<div class="ModuleGridBorder">
	<!-- 表格内容开始 -->
	<div id="tableDivId">
	<div id="winEL"></div>
	</div>
	<!-- 表格内容 结束 -->
	</div>
	</div>	
	
	<div>
			    <!-- 编辑区域 -->
			  <div class="ModuleEdit">
			    <div class="ModuleEditBorder">
				<div class="ModuleEditButton">
					<!--按钮 -->
				    <g:button disabled="true" styleId="btnSave" styleClass="new" type="button" text="button.save" onclick="javascript:FormUtils.clearForm('dictDetailForm');"/>
					<!--按钮 -->
				    <g:button styleId="btnNew" styleClass="delete" type="button" text="button.new" />
					<!--按钮 -->
				    <g:button styleId="btnDelete" styleClass="cancel" type="button" text="button.delete"/>
				    <!--按钮 -->
				    <g:button disabled="true" styleId="btnCancel" styleClass="cancel" type="button" text="button.cancel"/>
				</div>
				<div class="Line"></div>
				<div id="editFormDiv" style="display:none;">
				    <form id="editForm" onsubmit="return false;">
				    <input type="hidden" name="roleId" id="hiddenRoleId" >
					<table width="100%" class="ModuleEditInput">
							<tr>
								<td width="10%"><g:label text="system.Role.roleName" allowBlank="false"/></td>
								<td width="22%"><g:text property="roleName"></g:text></td>
								<td width="10%"><g:label text="system.Role.roleDesc"/></td>
								<td width="22%"><g:text property="roleDesc"/></td>
								<td width="10%"><g:label text="system.Role.roleType" allowBlank="false" /></td>
								<td width="22%">
									<g:combox kind="select" property="roleType">
										<g:option value="1">Active</g:option>
										<g:option value="2">Lock</g:option>
										<g:option value="3">Disable</g:option>
									</g:combox>
								</td>
							</tr>
							<tr>
								<td width="10%"><g:label text="system.Role.officeCode"/></td>
								<td><g:combox kind="associate" property="officeCode" styleId="officeCode"></g:combox>
								</td>
								
								<td><g:label text="system.ActiveDate" allowBlank="false" /></td>
								<td><g:date property="activeDate" dateFormat="yyyy-MM-dd" /></td>
								<td><g:label text="system.ExpiredDate" allowBlank="false" /></td>
								<td><g:date property="expiredDate" dateFormat="yyyy-MM-dd"/></td>
							</tr>	
					</table>
					</form>
				</div>
			    </div>
			  <!-- 编辑区域 -->
	</div>
</div>
</div>
</body>
<ge:body>
	<ge:window id="win">
		<ge:grid.baseGrid 
			queryObjectName="com.wef.system.entity.Role"
			dwrService="RoleService"
			dwrMethod="saveOrUpdateRoles"
			searchFormId="searchForm" 
			editFormId="editForm" 
			searchBtnId="btnSearch"
			saveBtnId="btnSave"
			newBtnId="btnNew"
			deleteBtnId="btnDelete"
			cancelBtnId="btnCancel"
			loadMask="true" 
			id="gridRoleManager"
			bodyStyle="width:100%"
			autoWidth="true"
			height="210"
			readerFields="roleName,roleDesc,officeCode,activeDate,expiredDate,roleType"
			enableHdMenu="false"
			beforeSaveFunc="validateCode"
			showExportAllToExcel="false"
			showExportToExcel="false"
			>
			<ge:grid.columnModel>
				<ge:grid.rowNumberer />
				<ge:grid.column header="system.Role.roleName" dataIndex="roleName">
				</ge:grid.column>
				<ge:grid.column header="system.Role.roleDesc" dataIndex="roleDesc" width="300" >
				</ge:grid.column>
				<ge:grid.column header="system.Role.officeCode" dataIndex="officeCode">
				</ge:grid.column>
				<ge:grid.column header="system.Role.activeDate" dataIndex="activeDate" renderer="Ext.util.Format.dateRenderer('Y-m-d')">
				</ge:grid.column>
				<ge:grid.column header="system.Role.expiredDate" dataIndex="expiredDate" renderer="Ext.util.Format.dateRenderer('Y-m-d')">
				</ge:grid.column>
				<ge:grid.column header="system.Role.roleType" dataIndex="roleType" renderer="renderRoleType" >
				</ge:grid.column>
			</ge:grid.columnModel>
		</ge:grid.baseGrid>
	</ge:window>
</ge:body>
<ge:onReady>
	setTimeout(function(){
		gridRoleManager.render('winEL');
		gridRoleManager.store.load();
	}, 1);
</ge:onReady>
</html>